/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view;

import java.awt.BorderLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JToggleButton;

import soccerscope.view.layer.Layer;

public class StatusBar extends JPanel {

    private static final long serialVersionUID = -7770955411437285733L;

    // private FieldPane fieldPane;

    // private InfoBar infoBar;

    private JLabel statusLabel;

    private JProgressBar progressBar;

    // private Color foregroundColor;

    // private Color backgroundColor;

    public StatusBar(ScopePane scopePane) {
        super();

        // this.fieldPane = scopePane.getFieldPane();
        // this.infoBar = scopePane.getInfoBar();

        this.statusLabel = new JLabel("status");
        this.progressBar = new JProgressBar();
        // this.foregroundColor = this.statusLabel.getForeground();
        // this.backgroundColor = this.statusLabel.getBackground().darker();

        this.setLayout(new BorderLayout());
        JPanel jp = new JPanel();
        jp.add(this.statusLabel);
        jp.add(this.progressBar);
        this.add(jp, BorderLayout.WEST);
        JPanel jp2 = new JPanel();
        ArrayList list = scopePane.getShowLayer();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Layer layer = (Layer) it.next();
            JToggleButton button = layer.createJToggleButton();
            button.setText(null);
            try {
                button.setIcon(new ImageIcon(ScenePlayer.class
                        .getResource("/soccerscope/image/" + layer.getLayerName()
                                + ".gif")));
            } catch (NullPointerException e) {
                System.err.println("Image for Layer not found: /soccerscope/image/"
                        + layer.getLayerName() + ".gif");
                button.setText("<html>" + layer.getLayerName()
                        .replaceAll("([A-Z])", "<br>$1")
                        .replaceAll("(<br>[^<>][^<>][^<>][^<>])[^<>]*", "$1")
                        .replaceFirst("<br>", "")
                        .replaceAll("([^<>]*<br>[^<>]*).*", "$1")
                                + "</html>");
            }
            button.setSize(20, 20);

            button.setMargin(new Insets(0, 0, 0, 0));
            jp2.add(button);
        }
        this.add(jp2, BorderLayout.CENTER);

        setVisible(true);
    }

    public JProgressBar getProgressBar() {
        return this.progressBar;
    }

    public void setStatus(String s) {
        this.statusLabel.setText(s);
    }
}
